package com.jeesite.modules.stock.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jeesite.modules.stock.dao.mapper.StockLogoMapper;
import com.jeesite.modules.stock.entity.StockLogoEntity;

@Component
public class StockLogoDao {

	@Autowired
	private StockLogoMapper stockLogoMapper;
	
	public void insert(StockLogoEntity entity) {
		stockLogoMapper.insert(entity);
	} 
	
	public void update(StockLogoEntity entity) {
		stockLogoMapper.update(entity);
	}
	
	public void saveOrUpdate(StockLogoEntity entity) {
		if(exist(entity.getStockCode())) {
			update(entity);
		} else {
			insert(entity);
		}
	}
	
	public boolean exist(String stockCode) {
		StockLogoEntity entity = new StockLogoEntity();
		entity.setStockCode(stockCode);
		return stockLogoMapper.findCount(entity)>0;
	}
	
	public StockLogoEntity getLogoByStockCode(String stockCode) {
		StockLogoEntity entity = new StockLogoEntity();
		entity.setStockCode(stockCode);
		List<StockLogoEntity> list = stockLogoMapper.findList(entity);
		
		if(list==null || list.isEmpty()) {
			return null;
		}
		return list.getFirst();
	}
}
